/**
 * AI动作类
 */
var AIEvent = function() {
	//叫牌标签
	this._action = { allIn:3, raise:1, call:0, check:4, fold:2 };	
	//this._action = ['call', 'raise', 'fold', 'allIn', 'check', 'check'];//0,1,2,3,4	
}
/**
 * 
 */
AIEvent.prototype.deal = function(r_room, r_user) {
	var _level = parseInt(r_user.getVariable("level").value);
	if (parseInt(r_user.getVariable("level").value) < 100) {
		return;		
	}
	var _do = { };
	switch(_level) {
		case 100://easy
			_do = (new AIEasy()).getDo(r_room,r_user);
			break;
		case 101://hard
			
			break;
		case 102://crazy
			
			break;
	}
	_pokerAc.bet(r_room, r_user, _do);
	return;
	
	
	var _AIRules = new AIRules();
	//取得电脑牌
	var _user_poker = r_user.properties.get("poker");
	//根据发牌次数取得已发公共牌
	var _deals = parseInt(r_room.getVariable("deals").value);
	var _pub_poker = r_room.properties.get("pubPoker");
	_pub_poker = _pub_poker.slice(0, (_deals + 1));
	//计算电脑牌的权值
	var _sort_user_poker = _AIRules.getFormatPoker(_user_poker, _pub_poker);
	var _user_max_poker = _AIRules.getMaxRules(_sort_user_poker);
	var _user_weight = _AIRules.getPokerWeight(_user_max_poker);	
	var _fold_lv = factorial(3, _deals) +20;
	_fold_lv = Math.floor((100 - parseInt(_user_weight['allIn']['lv'])) * _fold_lv / 200);
	_user_weight['allIn']['lv']  *= 0.5;
	_user_weight['fold'] = { lv:_fold_lv, bv:0 };
	_user_weight['call'] = { lv:50, bv:4 };
	//判断是否添加check
	var _pot = parseInt(r_room.getVariable("pot").value);
	var _call = parseInt(r_room.getVariable("call").value);	
	var _bank = parseInt(r_user.getVariable("bank").value);
	if (_deals != 0 && _pot ==0 && _call == 0) {
		_user_weight['check'] = { lv:50, bv:4 };
		_user_weight['call'] = { lv:0, bv:0 };
	}
	var _action_weight = [];
	for (var _weg in _user_weight) {
		var _obj = [];
		_obj = [_weg, _user_weight[_weg]['lv']];		
		_action_weight.push(_obj);
	}
	var _type = this.getAction(_action_weight);
	var _param = { };
	_param['way'] = this._action[_type];	
	_param['chip'] = 0;
	switch(_type) {
		case "call":
			//跟注别人的check
			if (r_room.getVariable("call").value == 0) {
				_param['way'] = this._action['check'];
			}
			break;
		case "raise":
			//加注别人的加注或allIn
			var _max_blind = r_room.getVariable("maxBlind").value;
			var _user_bet = _call +getRandom(1, 5) * _max_blind;
			_param['chip'] = _user_bet;
			if (_bank <= _user_bet) {
				_param['way'] = this._action['allIn'];
			}			
			break;
		case "allIn":
			_param['chip'] = parseInt(r_user.getVariable("bank").value);
			break;
	}
	_pokerAc.bet(r_room, r_user, _param);
}



/**
 * 电脑发送大小盲注
 * 
 */
AIEvent.prototype.doBlind = function(r_room, r_user, r_type) {		
	var _blind_type = (r_type == 'small') ? 'minBlind' : 'maxBlind';
	var _blind = parseInt(r_room.getVariable(_blind_type).value);
	var _params = { way:5, chip:_blind };
	_pokerAc.bet(r_room, r_user, _params);
}
/**
 * 取得叫牌类型
 * 
 */
AIEvent.prototype.getAction = function(r_param) {
	__log.show(r_param);
	var _count = r_param.length;
	_count--;
	while (1==1) {
		var _rand = getRandom(0, _count);
		var _lv = getRandom(0, 100);
		if (r_param[_rand][1] >= _lv) {
			return r_param[_rand][0];
		}
	}	
	return;
}
